<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class helper_common {

    public static function page($array, $pagesize, $page_num) {

        $size = empty($pagesize) ? 3 : $pagesize;
        $pnum = ceil(count($array) / $size);
        if ($page_num) {
            $page = intval($page_num);
            $page = $page > $pnum ? $pnum : $page;
            $page = $page < 1 ? 1 : $page;
        } else {
            $page = 1;
        }
        $result = array();
        for ($i = 0; $i < $size; $i++) {
            if (!isset($array[($page - 1) * $size + $i])) {
                break;
            }
            $result[] = $array[($page - 1) * $size + $i];
        }
        $result['page'] = $page;
        $result['pnum'] = $pnum;
        return $result;
    }

    public static function microtime_float() {
        //	获取毫秒的时间戳
        $time = explode(" ", microtime());
        $time = $time [1] . ($time [0] * 1000);
        $time2 = explode(".", $time);
        $time = $time2 [0];
        return $time;
    }

}
